package com.hmall.trade.listener;

import com.hmall.common.constants.MqConstants;
import com.hmall.trade.service.IOrderService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.annotation.Exchange;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.QueueBinding;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

/**
 * @author zzw
 * @date 2025/6/21
 * @description 消费消息，修改订单状态
 */
@Component
@Slf4j
@RequiredArgsConstructor
public class PayStatusListener {

    private final IOrderService orderService;


    @RabbitListener(bindings = @QueueBinding(
            value = @Queue(MqConstants.PAY_SUCCESS_QUEUE),
            exchange = @Exchange(MqConstants.PAY_EXCHANGE_NAME),
            key = MqConstants.PAY_SUCCESS_KEY
    )
    )
    public void listenPaySuccess(Long payOrderNo) {
        log.info("支付成功，修改订单状态");
        orderService.markOrderPaySuccess(payOrderNo);
    }
}
